home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Tetris Light 1.0 / source / about.c next >
Text File  |  1993-07-18  |  3KB  |  102 lines

  1. /**********************************************************************\
  2.  
  3. File:        about.c
  4.  
  5. Purpose:    This module handles the displaying of the about box.
  6.  
  7.  
  8. ``Tetris Light'' - a simple implementation of a Tetris game.
  9. Copyright (C) 1993 Hoylen Sue
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program; see the file COPYING.  If not, write to the
  23. Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25. \**********************************************************************/
  26.  
  27. #include "local.h"
  28. #include "about.h"
  29. #include "dialutil.h"
  30. #include "resources.h"
  31. #include "windows.h"
  32.  
  33. /*--------------------------------------------------------------------*/
  34.  
  35. static pascal Boolean about_filter_proc(DialogPtr dp, EventRecord *evt,
  36.                                         INTEGER *itemhit)
  37. /* Filter proc for the dialog.  Traps mouseDown events anywhere to
  38.    remove the dialog.  Pressing the return or enter key also removes
  39.    the dialog.  Processes activateEvt and updateEvt normally, so that
  40.    windows behind it get updated correctly. */
  41. {
  42.     INTEGER type;
  43.     Handle handle;
  44.     Rect box;
  45.     Point local;
  46.     
  47.     switch (evt->what) {
  48.     case mouseDown:
  49.         local = evt->where;
  50.         SetPort(dp);
  51.         GlobalToLocal(&local);
  52.         GetDItem(dp, OK, &type, &handle, &box);
  53.         if (!PtInRect(local, &box)) {
  54.             /* Was not pressed inside (near enough) the button */
  55.             *itemhit = OK;
  56.             return TRUE;
  57.         }
  58.         break;
  59.     case keyDown:
  60.         if ((evt->message & charCodeMask) == ENTER_CODE ||
  61.             (evt->message & charCodeMask) == RETURN_CODE) {            
  62.             simulate_key_hit(dp, OK);
  63.             *itemhit = OK;
  64.             return TRUE;
  65.         }
  66.         break;
  67.     case activateEvt:
  68.         if (dp != (WindowPtr) evt->message) {
  69.             if (evt->modifiers & activeFlag)
  70.                 window_activate((WindowPtr) evt->message);
  71.             else
  72.                 window_deactivate((WindowPtr) evt->message);
  73.         }
  74.         break;
  75.     case updateEvt:
  76.         if (dp != (WindowPtr) evt->message)
  77.             window_update((WindowPtr) evt->message);
  78.         break;
  79.     }
  80.  
  81.     return FALSE;
  82. }
  83.  
  84. /*--------------------------------------------------------------------*/
  85.  
  86. void about_box(void)
  87. /* Brings up the about box, and processes it until the user makes it
  88.    go away.  The dialog box is removed if the mouse is pressed or the
  89.    return or enter key is pressed. */
  90. {
  91.     DialogPtr    dial;
  92.     INTEGER        item;
  93.     
  94.     dial = GetNewDialog(ABOUT_DIAL_ID, NIL, (WindowPtr) -1);
  95.     install_hilight_button(dial, OK, ABOUT_HIGHLIGHT_ITEM);
  96.     ModalDialog(about_filter_proc, &item);
  97.     DisposDialog(dial);
  98. }
  99.  
  100. /*--------------------------------------------------------------------*/
  101.  
  102.